<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui,chosen'}){%>
    <style type="text/css">
        body{padding-top:10px;
            padding-left: 10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>
<div class="row">
    <div class="col-sm-12">
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-horizontal">
                    <input type="hidden" readonly id="productMember" name="productMember" class="form-control" value="${user.userRealname}">
                    <div class="form-group">
                        <label class="control-label col-sm-1">供应商:</label>
                        <div class="col-sm-2">
                            <select  id="productSupplierId" name="productSupplierId" xm-select="supplierId" xm-select-radio xm-select-search>
                                <%for(var dict in supplier){%>
                                <option value="${dict.id}">${dict.supplierName}</option>
                                <%}%>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">渠道:</label>
                        <div class="col-sm-2">
                            <select  id="productChannelId" name="productChannelId" xm-select="channel" xm-select-radio xm-select-search>
                                <%for(var dict in channel){%>
                                <option value="${dict.id}">${dict.channelName}</option>
                                <%}%>
                            </select>
                        </div>
                        <label class="control-label col-sm-1">SKU:</label>
                        <div class="col-sm-2">
                            <input type="text" id="productSku" name="productSku" class="form-control">
                        </div>
                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>
                </form>
            </div>
            <!-- START 操作按钮 -->
            <form>
                <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                    <button  class="add-btn layui-btn layui-btn-normal layui-btn-sm" >
                        <i class="fa fa-plus" aria-hidden="true"></i> 新增
                    </button>
                    <button  class="layui-btn layui-btn-sm import-btn" style="margin-left: -2px"  id="import-btn"  name="import-btn">
                        <i class="layui-icon"></i>导入SKU价格变动
                    </button>
                    <button  class="layui-btn  layui-btn-sm" >
                        <i class="fa fa-download"></i>
                        <a href="/excel/供应商报价模板.xlsx" style="color: white" download>模板下载</a>
                    </button>
                    <button  class="export-btn layui-btn  layui-btn-sm" style="margin-left: -2px">
                        <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
                    </button>
                    <button  class="export-history-btn layui-btn  layui-btn-sm" style="margin-left: -2px">
                        <i class="fa fa-download" aria-hidden="true"></i> 导出历史变动数据
                    </button>
                </div>
            </form>
            <!-- END 操作按钮 -->

            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-url="/sea/supply/productPrice/findByCnd.do"
                   data-page-size="15"
                   class="table table-striped table-hover"
            >
            </table>
            <!-- END 数据表格 -->
        </div>
    </div>
</div>
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,bootstrap-table-zh-CN,dtvalidate,dtvalidate-lang-zh_cn,laydate,layer,layui,chosen,chosen-demo,upload'}){}%>
<script>
    var $relatedTable = $('#relatedTable');
    $(function(){
        //START 表格配置
        $relatedTable.bootstrapTable({
            columns: [
                {
                    title: '供应商',
                    field: 'productSupplierName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '渠道',
                    field: 'productChannelName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '币种',
                    field: 'productMoneyType',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: 'SKU',
                    field: 'productSku',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '最新含税价格',
                    field: 'productPrice',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '不含税价格',
                    field: 'productUnitPrice',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '最新含税价格(RMB)',
                    field: 'productPriceCny',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '不含税价格(RMB)',
                    field: 'productUnitPriceCny',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '税率',
                    field: 'productPercent',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '更新时间',
                    field: 'modifyTime',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                //修改按钮
                $('.edit-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.open({
                        title: false,
                        closeBtn: 0,
                        type: 2,
                        area: ['100%','100%'],
                        skin: 'layer-ext-espresso',
                        content: ['/sea/supply/productPrice/editPage.do?id='+id, 'yes']
                    });
                });
                $('.del-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.confirm('确定要删除当前？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        $.post('/sea/supply/productPrice/delete.do',{id: id},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $relatedTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                    });
                });
                $('.record-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.open({
                        title: false,
                        type: 2,
                        closeBtn:false,
                        area: ['100%','100%'],
                        content: ['/sea/supply/productPriceRecord/main.do?id='+id, 'yes']
                    });
                });
            }
        });
        //新增
        $('.add-btn').on('click',function(){//新增
            layer.open({
                title: false,
                closeBtn: 0,
                type: 2,
                area: ['100%','100%'],
                skin: 'layer-ext-espresso',
                content: ['/sea/supply/productPrice/addPage.do', 'yes']
            });
        });
        $('.search-btn').on('click',function(){
            $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/supply/productPrice/findByCnd?'+$('#search-form').serialize() });
        });

        //操作菜单
        function optFormatter(value,row){
            var content= '';
            content+='<button class="edit-btn btn btn-xs btn-info" data-val="' + row.id + '" title="修改"><i class="fa fa-edit"></i>  </button>';
            content+='<button class="del-btn btn btn-xs btn-danger" data-val="' + row.id + '" title="删除" style="margin-left: 5px;"><i class="fa fa-trash"></i>  </button>';
            content+= '<button class="record-btn btn btn-xs btn-default" style="margin-left: 5px;" data-val="'+row.id+'" title="价格变动记录">价格变动记录</button>';
            return content;
        }
    });

    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: '#import-btn', //绑定元素,
            accept:'file',
            url: '/sea/supply/productPrice/import/', //上传接口
            data:{"productMember":$("#productMember").val()},
            before:function () {
                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $relatedTable.bootstrapTable('refresh');
                        layer.closeAll();
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,time: 5000},function () {
                        layer.closeAll();
                    });

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });

    $(".export-btn").click(function () {
        window.location.href='/sea/supply/productPrice/export?'+$('#search-form').serialize();
    });

    $(".export-history-btn").click(function () {
        window.location.href='/sea/supply/productPrice/exportHistory?'+$('#search-form').serialize();
    });

</script>
</body>
</html>
